import { Controller, Get, Post, Body } from '@nestjs/common';
import { interfaceBooks } from './interface/books.interface';
import { BookDto } from './dto/book.dto';
import { BooksService } from './books.service';
@Controller('books')
export class BooksController {
  constructor(private readonly booksService: BooksService) {}
  @Get('list')
  async getBooks(): Promise<interfaceBooks[]> {
    return await this.booksService.findAll();
  }
  @Post('add')
  async addBooks(
    @Body() addBookDto: BookDto,
  ): Promise<{ message: string; success: boolean }> {
    return await this.booksService.create(addBookDto);
  }
  @Post('edit')
  async editBooks(
    @Body() params: BookDto,
  ): Promise<{ message: string; success: boolean }> {
    return await this.booksService.update(params);
  }
  @Post('delete')
  async deleteBooks(
    @Body() params: { id: number },
  ): Promise<{ message: string; success: boolean }> {
    return await this.booksService.delete(params);
  }
}
